package com.example.day11_7_11_2.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import butterknife.ButterKnife;


//所有项目中Activity的父类
//模板方法模式:父类定义执行的流程,有一些操作需要延迟到子类完成
public abstract class BaseActivity<P extends BasePresenter>
        extends AppCompatActivity implements BaseView {

    public P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //父类不能决定子类的界面布局
        setContentView(getLayout());
        ButterKnife.bind(this);
        mPresenter = initPresenter();
        if (mPresenter != null){
            mPresenter.bindView(this);
        }
        initView();
        initData();
    }

    protected abstract P initPresenter();

    protected abstract void initData();

    protected abstract void initView();

    protected abstract int getLayout();

    //所有activity销毁的时候都需要做的事情
    //1.取消网络请求
    //2.取消V和P层关联
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //1.取消网络请求
        mPresenter.onDestory();
        //2.取消V和P层关联
        mPresenter = null;
    }
}
